#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

struct castle
{
	castle(int i_a, int i_m):a(i_a), m(i_m){}
	castle(){}
	int a, m;
};

bool operator<(const castle& i_castle1, const castle& i_castle2)
{
	return (i_castle1.a - i_castle1.m < i_castle2.a - i_castle2.m);
}

class D 
{
public:
	void init();
	int solve();
	int get_start_p();
	void approach(int p);
private:
	vector<castle> army;
	vector<set<int> > link;
	vector<bool> use;
	int n;
	int start_p;
};

void D::init()
{
	cin >> n;
	if (n)
	{
		army = vector<castle>(n);
		link = vector<set<int> >(n);
		use = vector<bool>(n, false);

		for (int i = 0; i < n; ++i)
		{
			int a, m, p;
			cin >> a >> m >> p;
			army[i] = castle(max(a, m + p), m + p);
		}

		for (int i = 0; i < n - 1; ++i)
		{
			int p1, p2;
			cin >> p1 >> p2;
			link[p1].insert(p2);
		}
	}
}

int D::get_start_p()
{
	start_p = 0;
	for (int i = 1; i < n; ++i)
	{
		if (army[i].a - army[i].m > army[start_p].a - army[start_p].m)
			start_p = i;
	}
	return start_p;
}

void D::approach(int p)
{
	vector<castle> local_army;
	use[p] = true;
	
	for (set<int>::iterator iter = link[p].begin(); iter != link[p].end(); ++iter)
	{
		if (!use[*iter])
		{
			local_army.push_back(army[*iter]);
			approach(*iter);
		}
	}

	sort(local_army.begin(), local_army.end());
	
	int sum_req = army[p].a - army[p].m;
	int sum_die = 0;

	int current = sum_req;
	for (vector<castle>::iterator iter = local_army.begin(); iter != local_army.end(); ++iter)
	{
		if (current < iter->a)
		{
			sum_req += iter->a - current;
			current = iter->a;
		}
		current -= iter->m;
		sum_die += iter->m; 
	}

	army[p].a += sum_req;
	army[p].m += sum_die;
}

int D::solve()
{
	if (!n)
		return -1;

	approach(get_start_p());
	return army[start_p].a;
}

int main()
{
	while (true)
	{
		D task;
		task.init();
		int solve = task.solve();
		if (solve == -1)
			break;
		else
			cout << solve << endl;
	}
}